package com.offcn;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class OssUpload {

    public static void main(String[] args) throws FileNotFoundException {
        //创建Endpoint 网关接入地址
        String endpoint="https://oss-cn-guangzhou.aliyuncs.com";
        //accessKeyId
        String accessKeyId="LTAI5tHj2UnNwLftape8Npb1";
        //accessKeySecret
        String accessKeySecret="PDnIO3PYOtQFBUPTDQL7mZib7o8CNj";

        //创建OssClient
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        //准备一个本地文件
        File file = new File("E:\\pic\\1.jpg");
        //创建一个输入流读取文件
        FileInputStream inputStream = new FileInputStream(file);

        //调用ossClient执行文件的上传
        ossClient.putObject("ujiuye001","pic/001.jpg",inputStream);

        //关闭输入流
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //关闭ossClient
        ossClient.shutdown();

        System.out.println("文件上传oss成功");

    }
}
